package com.ruoyi.law.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageCondition;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.law.domain.dto.LawAuditDTO;
import com.ruoyi.law.domain.entity.LawLawyer;
import com.ruoyi.law.service.ILawLawyerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 律师申请表 前端控制器
 * </p>
 *
 * @author code
 * @since 2022-11-30
 */
@Api(tags = "律师申请管理")
@RestController
@RequestMapping("/lawyer")
public class LawLawyerController extends BaseController {

    @Autowired
    private ILawLawyerService lawyerService;

    @ApiOperation("列表")
    @GetMapping("/list")
    public R<Page<LawLawyer>> list(PageCondition<LawLawyer> pageCondition) {
        Page<LawLawyer> page = lawyerService.page(pageCondition.toPage());
        return R.ok(page);
    }

    @ApiOperation("详情")
    @GetMapping("/info")
    public R<LawLawyer> info(Long id) {
        LawLawyer vip = lawyerService.getById(id);
        return R.ok(vip);
    }

    @ApiOperation("新增")
    @PostMapping("/save")
    public R<Object> save(@RequestBody LawLawyer lawLawyer) {
        lawLawyer.setUserId(SecurityUtils.getUserId());
        lawyerService.save(lawLawyer);
        return R.ok();
    }

    @ApiOperation("修改")
    @PostMapping("/update")
    public R<Object> update(@RequestBody LawLawyer lawLawyer) {
        lawyerService.updateById(lawLawyer);
        return R.ok();
    }

    @ApiOperation("删除")
    @PostMapping("/delete")
    public R<Object> delete(@RequestBody Long id) {
        lawyerService.removeById(id);
        return R.ok();
    }

    @ApiOperation("审核")
    @PostMapping("/audit")
    public R<Object> audit(@Validated @RequestBody LawAuditDTO auditDTO) {
        lawyerService.audit(auditDTO);
        return R.ok();
    }

}
